package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.mapper.AccidentDetailMapper;
import cn.wolfcode.crm.query.impl.AccidentDetailQuery;
import cn.wolfcode.crm.service.IAccidentDetailService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("auditBill")
public class AuditBillController {
    @Autowired
    IAccidentDetailService accidentDetailService;
    @Autowired
    AccidentDetailMapper accidentDetailMapper;

    @RequestMapping("view")
    @RequiresPermissions(value = {"auditBill:view","事故审核页面"},logical= Logical.OR)
    public String view() {
        return "auditBill";
    }
    @RequestMapping("loss")
    @RequiresPermissions(value = {"auditBill:view","事故审核页面"},logical= Logical.OR)
    public String loss() {
        return "loss";
    }


    @RequestMapping("query")
    @ResponseBody
    public PageResult query(AccidentDetailQuery qo) {
        return accidentDetailService.queryByState(qo);
    }
    @RequestMapping("queryByCheck")
    @ResponseBody
    public PageResult queryByCheck(AccidentDetailQuery qo) {
        return accidentDetailService.queryByCheck(qo);
    }

    @RequestMapping("changeState")
    @RequiresPermissions(value = {"auditBill:change","更改审核状态"},logical= Logical.OR)
    @ResponseBody
    public JSONResult changeState(Long id){
        try {
            accidentDetailService.changeCheckState(id);
        } catch (Exception e) {
            e.printStackTrace();
            accidentDetailMapper.changeCheckState(id ,true);
            return new JSONResult(false,e.getMessage());
        }
        return new JSONResult(true,"状态更新成功");
    }
}
